package net.microfigure.mapper;

import net.microfigure.model.PartInst;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.mapper.BaseMapper;

/**
 * <p>
  * 参合登记实例表 Mapper 接口
 * </p>
 *
 * @author 林景锋
 * @since 2018-06-22
 */
@Mapper
public interface PartInstMapper extends BaseMapper<PartInst> {

	@Insert("insert into "
			+ "part_inst(part_no,family_no,name,gender,age,contact,address) "
			+ "values(#{familyNo},#{name},#{gender},#{age},#{contact},#{address})")
	boolean insertOK(PartInst partInst);

	@Select("SELECT CONCAT(family_no,LPAD(SUBSTR(max(part_no),15)+1,2,0)) "
			+ "as part_no from part_inst where family_no=#{preFix}")
	String sQLQuery(String preFix);

	@Select("select part_no AS partNo,family_no AS familyNo,"
			+ "name,gender,age,contact,address,part_time AS partTime,invo_no AS invoNo,id,family_info_no AS familyInfoNo "
			+ "from part_inst where family_info_no = #{familyInfoNo}")
	List<PartInst> selectListByFamilyInfoNo(Integer familyInfoNo);
	
	@Select("select part_no AS partNo,family_no AS familyNo,"
			+ "name,gender,age,contact,address,part_time AS partTime,invo_no AS invoNo,id,family_info_no AS familyInfoNo "
			+ "from part_inst part_inst where part_no = #{partNo}")
	PartInst selectBypartNo(String partNo);

	
	@Delete("delete from part_inst where part_no = #{partNo}")
	void deleteByPartNo(String partNo);

	

}